/* eslint-disable no-useless-escape */
/**
 * @description: 数字转金额格式
 * @param {*} s num
 */
export const formatMoney = (s) => {
  if (/[^0-9\.]/.test(s)) return "invalid value";
  s = s.replace(/^(\d*)$/, "$1.");
  s = (s + "00").replace(/(\d*\.\d\d)\d*/, "$1");
  s = s.replace(".", ",");
  var re = /(\d)(\d{3},)/;
  while (re.test(s)) s = s.replace(re, "$1,$2");
  s = s.replace(/,(\d\d)$/, ".$1");
  return s.replace(/^\./, "0.");
};

/**
 * @description:  金额转数字
 * @param {*} money
 * @return {*}
 */
export const moneyToNumFiled = (money) => {
  var num = money.trim();
  var ss = num.toString();
  if (ss.length == 0) {
    return 0.0;
  }
  num = new Number(ss.replace(/,/g, ""));
  money = num;
};
